package android07.newtop.presenter;

import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.widget.Toast;

import com.jude.beam.expansion.data.BeamDataActivityPresenter;

import android07.newtop.R;
import android07.newtop.activity.WeatherActivity;
import android07.newtop.adapter.WeatherPagerAdapter;
import android07.newtop.model.WeatherBeanModel;
import android07.newtop.model.bean.MainBean;
import android07.newtop.model.bean.WeatherInfoBean;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


/**
 * 主页
 * Created by hy on 2016/7/7.
 */
public class WeatherActivityPresenter extends BeamDataActivityPresenter<WeatherActivity, MainBean> {

    WeatherPagerAdapter myPagerAdapter;
    FragmentManager supportFragmentManager;

    private static final String TAG = WeatherActivityPresenter.class
            .getSimpleName();

    /**
     * activity 刚起床， 睁开眼的那一刻 执行
     *
     * @param view
     */
    @Override
    protected void onCreateView(final WeatherActivity view) {
        super.onCreateView(view);
        //睁开眼，要干啥 ，要喝奶
        Log.d(TAG, "onCreateView: ");
///getDataSubscriber().onNext( 给Activity 填充数据的方法
//        view.getTabLayout().setSelectedTabIndicatorColor(view.getResources().getColor(R.color.white));

        supportFragmentManager = getView().getSupportFragmentManager();
        replaceFragment(0);
        getView().getToolbar().setTitle(myPagerAdapter.getPageTitle(0));



    }

    public void replaceFragment(int position) {
        if (myPagerAdapter == null) {
            myPagerAdapter = new WeatherPagerAdapter(getView(), supportFragmentManager);
        }
        getView().getViewPager().setAdapter(myPagerAdapter);
        getView().getViewPager().addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

                getView().getToolbar().setTitle(myPagerAdapter.getPageTitle(position));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
//        getView().getTabLayout().setupWithViewPager(getView().getViewPager());

    }

}
